#include <iostream>
#include <vector>
using namespace std;

class Graph {
private:
  int numVertices;
  vector<vector<int>> adjacencyMatrix;
  vector<vector<int>> adjacencyList;
public:
  Graph(int vertices) : numVertices(vertices) {
    adjacencyMatrix.resize(numVertices, vector<int>(numVertices, 0));
    adjacencyList.resize(numVertices);
  }

  void addEdge(int src, int dest) {
    adjacencyMatrix[src][dest] = 1;
    adjacencyMatrix[dest][src] = 1;

    adjacencyList[src].push_back(dest);
    adjacencyList[dest].push_back(src);
  }

  void printAdjacencyMatrix() {
    cout << "邻接矩阵：" << endl;
    for (int i = 0; i < numVertices; i++) {
      for (int j = 0; j < numVertices; j++) {
        cout << adjacencyMatrix[i][j] << " ";
      }
      cout << endl;
    }
  }

  void printAdjacencyList() {
    cout << "邻接表：" << endl;
    for (int i = 0; i < numVertices; i++) {
      cout << i << ": ";
      for (int neighbor : adjacencyList[i]) {
        cout << neighbor << " ";
      }
      cout << endl;
    }
  }
};

int main() {
  int numVertices = 5;

  Graph graph(numVertices);

  graph.addEdge(0, 1);
  graph.addEdge(0, 4);
  graph.addEdge(1, 2);
  graph.addEdge(1, 3);
  graph.addEdge(1, 4);
  graph.addEdge(2, 3);
  graph.addEdge(3, 4);

  graph.printAdjacencyMatrix();
  graph.printAdjacencyList();

  return 0;
}